﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.Web.UI.HtmlControls;
using Baimasoft.FrameWork.Base;
using Baimasoft.Manage.SqlServerDAL;
using Baimasoft.Manage.SqlServerDAL;

public partial class BBS_NewTopic_Edit : System.Web.UI.Page
{
    protected string str1, str2, str3, str4, Name = "", SID, SName, AID, AName;
    CommClass MyCC = new CommClass();
    user Myuser = new user();
    Articles MyAT = new Articles();

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            SID = Request.QueryString["SectionID"].ToString().Trim();
            SName = Request.QueryString["SectionName"].ToString().Trim();
            AID = Request.QueryString["ArticleID"].ToString().Trim();
            AName = MyCC.FilterBadWords (Request.QueryString["ArticleName"].ToString().Trim());
        }
        catch
        {
            Response.Write("参数传递错误！");
            Response.End();
        }

        if (!this.IsPostBack)
        {
            SqlDataReader MyDr = MyAT .ReadArticleInfo (AID);
            if (MyDr.Read())
            {
                subject.Value = MyDr["Title"].ToString().Trim();
                Content.Text = MyDr["Content"].ToString().Trim();
            }
        }
    }
    protected void Submit_Click(object sender, ImageClickEventArgs e)
    {
        string str2 = (string)Session["Baimasoft_User_LogonID"]; // 

        str4 = subject.Value.ToString().Trim();
        str1 = Content.Text.ToString().Trim();

        if (str4.LastIndexOf("'") > -1)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('话题不能使用单引号！');</script>");
            return;
        }
        else if (str4 == "")
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('话题不能为空！');</script>");
            return;
        }
        else if (str1 == "")
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('内容不能为空！');</script>");
            return;
        }
        else
        {
            str1 = str1.Replace("'", "");
            string TheMaster;
            DataView MasterInfo = new DataView();
            TheMaster = Myuser.GetMasterUser(SID);
            string[] sStr1 = TheMaster.Split(',');
            TheMaster = sStr1[0];

            string sArticleAuthor = Myuser.GetArticleAuthor(AID);  //当前主题贴作者

            if ((str2 == "admin") || (str2 == TheMaster) || (str2 == sArticleAuthor))
            {
                string UserIP = Request.UserHostAddress;
                string UserDNS = Request.UserHostName;
                int back = MyAT.UpdateTopicSelf (str4, str1, UserIP, UserDNS, AID);
                if (back == 1)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功！');location.href='Articles_List.aspx?SectionID=" + SID + "&SectionName=" + SName + "&ArticleID=" + AID + "&ArticleName=" + AName + "'</script>");
                    return;
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改失败！');location.href='Articles_List.aspx?SectionID=" + SID + "&SectionName=" + SName + "&ArticleID=" + AID + "&ArticleName=" + AName + "'</script>");
                    return;
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('您无些权限！');</script>");
                return;
            }
        }
    }
    protected void Reset_Click(object sender, ImageClickEventArgs e)
    {
        subject.Value = "";
        Content.Text = "";
    }
}
